package com.dream.keigezhushou.Activity.acty.personal;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.activity.BaseActivity;
import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyRefundActivity extends BaseActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.lv_refund)
    ListView lvRefund;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_refund);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("退款");
    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //返回
                finish();
            }
        });

        //ListView创建适配器
        lvRefund.setAdapter(new RefundAdapter(this));

        clickItem();
    }

    public class RefundAdapter extends BaseAdapter {

        private Context context;
        int c = 8;
        public RefundAdapter(Context context) {
            this.context = context;
        }

        @Override
        public int getCount() {
            return c;
        }

        @Override
        public Object getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {

            RefundHolder mHolder = null;
            if (view == null){

                view = LayoutInflater.from(context).inflate(R.layout.layout_order_item,null);
                mHolder = new RefundHolder();

                mHolder.rlKind = (RelativeLayout)view.findViewById(R.id.rl_state_kind);
                mHolder.tvKind = (TextView)view.findViewById(R.id.tv_state_kind);

                view.setTag(mHolder);
            }else {

                mHolder = (RefundHolder)view.getTag();
            }

            mHolder.rlKind.setVisibility(View.GONE);
            if (i % 2 == 0){

                mHolder.tvKind.setText("退款成功");
            }else {
                mHolder.tvKind.setText("退款中");
            }

            mHolder.tvKind.setTextColor(getResources().getColor(R.color.colorRefund));

            return view;
        }

        class RefundHolder{

            RelativeLayout rlKind;
            TextView tvKind;

        }
    }

    //ListView的条目点击事假
    private void clickItem(){

        lvRefund.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Intent intent = new Intent(MyRefundActivity.this,RefundInfoActivity.class);
                startActivity(intent);
            }
        });

    }
}
